<template>
    <div class="app-container">
        <el-form :model="queryParams"
                 ref="queryForm"
                 :inline="true"
                 v-show="showSearch"
                 label-width="68px">
            <el-form-item label="标题"
                          prop="title">
                <el-input v-model="queryParams.title"
                          placeholder="请输入标题"
                          clearable
                          size="small"
                          @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="所属专科"
                          prop="belongToSpecialty">
                <el-input v-model="queryParams.belongToSpecialty"
                          placeholder="请输入所属专科"
                          filterable
                          clearable
                          size="small"
                          @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="医生专家"
                          prop="doctorSpecialist">
                <el-input v-model="queryParams.doctorSpecialist"
                          placeholder="请输入医生专家"
                          clearable
                          size="small"
                          @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="区域"
                          prop="area">
                <el-input v-model="queryParams.area"
                          placeholder="请输入区域"
                          clearable
                          size="small"
                          @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="医院"
                          prop="hospital">
                <el-input v-model="queryParams.hospital"
                          placeholder="请输入医院"
                          clearable
                          size="small"
                          @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="视频状态"
                          prop="videoState">
                <el-select v-model="queryParams.videoState"
                           placeholder="请选择视频状态"
                           clearable
                           size="small">

                    <el-option
                        v-for="dict in videoStateOptions"
                        :key="dict.dictValue"
                        :label="dict.dictLabel"
                        :value="dict.dictValue"
                    />
                </el-select>
            </el-form-item>
            <el-form-item label="使用情况"
                          prop="useType">
                <el-select v-model="queryParams.useType"
                           placeholder="请选择使用情况"
                           clearable
                           size="small">
                    <el-option label="请选择字典生成"
                               value="" />
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="cyan"
                           icon="el-icon-search"
                           size="mini"
                           @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh"
                           size="mini"
                           @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>

        <el-row :gutter="10"
                class="mb8">
            <el-col :span="1.5">
                <el-button type="primary"
                           icon="el-icon-plus"
                           size="mini"
                           @click="handleAdd"
                           v-hasPermi="['operater:video:add']">新增</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="success"
                           icon="el-icon-edit"
                           size="mini"
                           :disabled="single"
                           @click="handleUpdate"
                           v-hasPermi="['operater:video:edit']">修改</el-button>
            </el-col>
            <el-col :span="1.5">
                <el-button type="danger"
                           icon="el-icon-delete"
                           size="mini"
                           :disabled="multiple"
                           @click="handleDelete"
                           v-hasPermi="['operater:video:remove']">删除</el-button>
            </el-col>
            <right-toolbar :showSearch.sync="showSearch"
                           @queryTable="getList"></right-toolbar>
        </el-row>

        <el-table v-loading="loading"
                  :data="videoList"
                  @selection-change="handleSelectionChange">
            <el-table-column type="selection"
                             width="55"
                             align="center" />
            <el-table-column label="视频信息id"
                             align="center"
                             prop="id" />
            <el-table-column label="标题"
                             align="center"
                             prop="title" />
            <el-table-column label="缩略图"
                             align="center"
                             width="200"
                             prop="thumbnailId">

                <template slot-scope="scope">
                    <img :src="faceImg(scope.row.thumbnailId)"
                         alt="">
                </template>
            </el-table-column>
            <el-table-column label="名称"
                             align="center"
                             prop="videoName" />
            <el-table-column label="关键字"
                             align="center"
                             prop="keyWord" />
            <el-table-column label="简介"
                             align="center"
                             prop="synopsis" />
            <el-table-column label="所属专科"
                             align="center"
                             prop="belongToSpecialty" />
            <el-table-column label="医生专家"
                             align="center"
                             prop="doctorSpecialist" />
            <el-table-column label="区域"
                             align="center"
                             prop="area" />
            <el-table-column label="医院"
                             align="center"
                             prop="hospital" />
            <el-table-column label="视频状态"
                             align="center"
                             prop="videoState"
                :formatter="newsStateFormat"/>
            <el-table-column label="视频审核备注"
                             align="center"
                             prop="videoRemarks" />
            <el-table-column label="使用情况"
                             align="center"
                             prop="useType" />
            <el-table-column label="发布时间"
                             align="center"
                             prop="pubdate"
                             width="180">
                <template slot-scope="scope">
                    <span>{{ parseTime(scope.row.pubdate, '{y}-{m}-{d}') }}</span>
                </template>
            </el-table-column>
            <el-table-column label="作者"
                             align="center"
                             prop="author" />
            <el-table-column label="操作"
                             align="center"
                             class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini"
                               type="text"
                               icon="el-icon-edit"
                               @click="handleUpdate(scope.row)"
                               v-hasPermi="['operater:video:edit']">修改</el-button>
                    <el-button size="mini"
                               type="text"
                               icon="el-icon-view"
                               v-hasPermi="['operater:video:see']"
                               @click="handleSeeDetail(scope.row)">查看</el-button>
                    <el-button size="mini"
                               type="text"
                               icon="el-icon-delete"
                               @click="handleDelete(scope.row)"
                               v-hasPermi="['operater:video:remove']">删除</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total>0"
                    :total="total"
                    :page.sync="queryParams.pageNum"
                    :limit.sync="queryParams.pageSize"
                    @pagination="getList" />
    </div>
</template>

<script>
import {
    listVideo,
    getVideo,
    delVideo,
    addVideo,
    updateVideo,
    exportVideo,
} from '@/api/operater/video'
import { baseUrl } from '@/api/config'

export default {
    name: 'Video',
    components: {},
    data() {
        return {
            // 遮罩层
            loading: true,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 视频信息表格数据
            videoList: [],
            // 弹出层标题
            title: '',
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                title: null,
                thumbnailId: null,
                videoName: null,
                keyWord: null,
                synopsis: null,
                belongToSpecialty: null,
                doctorSpecialist: null,
                area: null,
                hospital: null,
                videoState: null,
                videoRemarks: null,
                useType: null,
                pubdate: null,
                author: null,
            },
            // 表单参数
            form: {},
            // 表单校验
            rules: {},
            videoStateOptions:null
        }
    },
    created() {
        this.getDicts("video_state").then(response => {
            this.videoStateOptions = response.data;
        });
        this.getList()
    },
    methods: {
        // 状态字典翻译
        newsStateFormat(row, column) {
            return this.selectDictLabel(this.videoStateOptions, row.videoState);
        },
        faceImg(id) {
            return baseUrl(id)
        },
        /** 查询视频信息列表 */
        getList() {
            this.loading = true
            listVideo(this.queryParams).then((response) => {
                this.videoList = response.rows
                this.total = response.total
                this.loading = false
            })
        },
        // 取消按钮
        cancel() {
            this.open = false
            this.reset()
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                title: null,
                thumbnailId: null,
                videoName: null,
                keyWord: null,
                synopsis: null,
                belongToSpecialty: null,
                doctorSpecialist: null,
                area: null,
                hospital: null,
                videoState: null,
                videoRemarks: null,
                useType: null,
                pubdate: null,
                author: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
            }
            this.resetForm('form')
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1
            this.getList()
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm('queryForm')
            this.handleQuery()
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map((item) => item.id)
            this.single = selection.length !== 1
            this.multiple = !selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
            this.$router.push('/article/editVideo')
            this.title = '添加视频信息'
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
            const id = row.id || this.ids
            this.$router.push('/article/editVideo?videoId=' + id)
            // getVideo(id).then(response => {
            //     this.form = response.data;
            //     this.open = true;
            //     this.title = "修改视频信息";
            // });
        },
        handleSeeDetail(row) {
            const id = row.id || this.ids
            this.$router.push('/article/seeVideo?videoId=' + id)
        },
        /** 提交按钮 */
        submitForm() {
            this.$refs['form'].validate((valid) => {
                if (valid) {
                    if (this.form.id != null) {
                        updateVideo(this.form).then((response) => {
                            this.msgSuccess('修改成功')
                            this.open = false
                            this.getList()
                        })
                    } else {
                        addVideo(this.form).then((response) => {
                            this.msgSuccess('新增成功')
                            this.open = false
                            this.getList()
                        })
                    }
                }
            })
        },
        /** 删除按钮操作 */
        handleDelete(row) {
            const ids = row.id || this.ids
            this.$confirm(
                '是否确认删除视频信息编号为"' + ids + '"的数据项?',
                '警告',
                {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                }
            )
                .then(function () {
                    return delVideo(ids)
                })
                .then(() => {
                    this.getList()
                    this.msgSuccess('删除成功')
                })
        },
        /** 导出按钮操作 */
        // handleExport() {
        //     const queryParams = this.queryParams;
        //     this.$confirm('是否确认导出所有视频信息数据项?', "警告", {
        //         confirmButtonText: "确定",
        //         cancelButtonText: "取消",
        //         type: "warning"
        //     }).then(function () {
        //         return exportVideo(queryParams);
        //     }).then(response => {
        //         this.download(response.msg);
        //     })
        // }
    },
}
</script>

<style lang="scss">
.app-container {
    .el-table {
        .cell {
            max-height: 100px;
            img {
                width: 100%;
            }
        }
    }
}
</style>
